
/*
Functions to allow:
unpack
math lib
Vector
Angle
Color

Additional:
ent/phys
player input
traces
toworld/tolocal
findinsphere
*/

luachip.validChars = {
	[33] = true, //!
	[34] = true, //"
	[35] = true, //#
	//[36] = true, //$ String only
	[37] = true, //%
	[38] = true, //&
	[39] = true, //'
	[40] = true, //(
	[41] = true, //)
	[42] = true, //*
	[43] = true, //+
	[44] = true, //,
	[45] = true, //-
	[46] = true, //.
	[47] = true, ///
	[58] = true, //:
	//[59] = true, //; String only
	[60] = true, //<
	[61] = true, //=
	[62] = true, //>
	//[63] = true, //? String only
	[91] = true, //[
	[92] = true, //\
	[93] = true, //]
	[94] = true, //^
	[95] = true, //_
	[123] = true, //{
	[124] = true, //|
	[125] = true, //}
	[126] = true, //~
}
for i=48,57 do
	luachip.validChars[i] = true
end
for i=65,90 do
	luachip.validChars[i] = true
end
for i=97,122 do
	luachip.validChars[i] = true
end

luachip.whiteSpace = {
	[9] = true, //\t
	[32] = true, // 
	[10] = true, //\n
}

luachip.charIsValid = function(chr)
	return luachip.validChars[string.byte(chr)]
end

luachip.charIsWhite = function(chr)
	return luachip.whiteSpace[string.byte(chr)]
end

luachip.charIsAlpha = function(chr)
	return (string.byte(chr) >= 65 and string.byte(chr) <= 90) or (string.byte(chr) >= 97 and string.byte(chr) <= 122)
end

luachip.charIsUpper = function(chr)
	return (string.byte(chr) >= 65 and string.byte(chr) <= 90)
end

luachip.charIsLower = function(chr)
	return (string.byte(chr) >= 97 and string.byte(chr) <= 122)
end

luachip.strIsAlpha = function(str)
	for i=1,#str do
		if not luachip.charIsAlpha(str:sub(i,i)) then
			return false
		end
	end
	return true
end

luachip.strIsAlphaNumeric = function(str)
	for i=1,#str do
		if not (luachip.charIsAlpha(str:sub(i,i)) or tonumber(str:sub(i,i))) then
			return false
		end
	end
	return true
end

luachip.expressionKeywords = {}
for k,v in pairs{ //These must all be lowercase
	"nil",
	"not",
	"and",
	"or",
	
	"true", //You cannot index a table with a boolean value, but you can index it with a string "true". However, you cannot do {true = "true"}, so hah!
	"false", //You cannot do tab.true = "test" either
} do
	luachip.expressionKeywords[v] = true
end

luachip.isExpressionKeyword = function(str)
	return luachip.expressionKeywords[str:lower()] or false
end

luachip.negationOperators = {}
for k,v in pairs{
	"not",
	"!",
} do
	luachip.negationOperators[v] = true
end

luachip.isNegationOperator = function(str)
	return luachip.negationOperators[str]
end

luachip.tableOperators = {}
for k,v in pairs{
	"[",
	"]",
	"{",
	"}",
	",",
	".",
	":",
} do
	luachip.tableOperators[v] = true
end

luachip.isTableOperator = function(str)
	return luachip.tableOperators[str]
end

luachip.expressionOperators = {}
for k,v in pairs{
	"and",
	"or",
	"&&",
	"||",
	"&",
	"|",
	"==",
	">=",
	"<=",
	">",
	"<",
	"~=",
	"!=",
	"%",
	"/",
	"*",
	"+",
	"-",
	"..",
	
	".",
	":",
	
	//"not",
	//"!",
} do
	luachip.expressionOperators[v] = true
end

luachip.isExpressionOperator = function(str)
	return luachip.expressionOperators[str]
end

luachip.operators = {}
for k,v in pairs{
	//"not",
	//"and",
	//"or",
	"&&",
	"||",
	"&",
	"|",
	"==",
	">=",
	"<=",
	"~=",
	"!=",
	"%",
	"/",
	"*",
	"+",
	"-",
	"!",
	
	":",
	
	"...", //Thought I wouldn't catch that one, did ya?
	
	"=",
	
	"(",
	")",
	"[",
	"]",
	"{",
	"}",
	",",
	".",
	"..",
} do
	luachip.operators[v] = true
end

luachip.stringOperators = {}
for k,v in pairs{
	'"',
	"'",
	"[[",
	"]]", //NOTE: THESE MUST BE PAIRED
} do
	luachip.stringOperators[v] = true
end

luachip.operatorsOrStringOperators = {}
for k,v in pairs(luachip.operators) do
	luachip.operatorsOrStringOperators[k] = true
end
for k,v in pairs(luachip.stringOperators) do
	luachip.operatorsOrStringOperators[k] = true
end

luachip.isOperator = function(str)
	return luachip.operators[str]
end

luachip.isStringOperator = function(str)
	return luachip.stringOperators[str]
end

luachip.isOperatorOrStringOperator = function(str)
	return luachip.operatorsOrStringOperators[str]
end

luachip.keywords = {}
for k,v in pairs{ //These must all be lowercase
	"local",
	"while",
	"repeat",
	"until",
	"for",
	"break",
	"do",
	"if",
	"in",
	"elseif",
	"else",
	"then",
	"end",
	"function",
	"return",
	"not",
	"and",
	"or",
	"nil",
	"true",
	"false",
} do
	luachip.keywords[v] = true
end

luachip.isKeyword = function(str)
	return luachip.keywords[str:lower()] or false
end

luachip.reservedVars = {}
for k,v in pairs{
} do
	luachip.reservedVars[v] = true
end

luachip.isReservedVar = function(str)
	return luachip.reservedVars[str] or false
end

/*
luachip.libraryVars = {}
for k,v in pairs(luachip.library) do
	luachip.libraryVars[v] = true
end

luachip.isLibraryVar = function(str)
	return luachip.libraryVars[str] or false
end
*/
luachip.isLibraryVar = function(str)
	return luachip.library[str] and true or false
end


/*
Key words:
local
while
repeat
until
for
break
do
if
elseif
then
end
function
return

nil

Operators:
not
and &&
or ||
&
|
%
==
>=
<=
!=
~=
/
*
-
+
*/

/*
Variable logic:
If there is a . or [, then make sure the table is local
*/
